@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
    <style>
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
        .autocomplete-button{
            display: none;
        }
        .proposal-list li{
            background-color: white !important;
        }
        li.proposal.selected{
            background-color: rgb(175, 42, 0) !important;
        }
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">用户管理</a>
            <em> > </em>
            <a href="#">用户列表</a>
        </div>
        <!-- cur-position end -->

        <!--二级目录-->
        @include('admin.common.user-header')

        <div class="filter-box clearfix">
            <div class="fl" style="display: inline-flex">
                <div class="sx">
                    <input class="gg-ipt" style="width: 180px;height: 26px" type="text" placeholder="输入昵称" name="nickname" id="nickname" value="{{$keyword}}" />
                </div>
                <div class="sx">
                    <button class="sx-btn" id="sou_btn">搜索</button>
                </div>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>头像</th>
                    <th>昵称</th>
                    <th>用户名</th>
                    <th>真实姓名</th>
                    <th>星座</th>
                    <th>地区</th>
                    <th>性别</th>
                    <th>阅读币</th>
                    <th>特殊设置</th>
                    <th>VIP设置</th>
                    <th>创建时间</th>
                    <th>账户状态</th>
                </tr>
                </thead>
                <tbody id="fansinfo">
                @if(count($users) > 0)
                    @foreach($users as $user)
                        <tr>
                            <td>{{$user->id}}</td>
                            <td class="account-td" style="width: 20px;">
                        <span class="photo">
                            <img src="{{$user->userInfo->photo_url}}" alt="">
                        </span>
                            </td>
                            <td>
                                <div class="info-box">
                                    <p>
                                        <span class="icon icon-rzh"></span>
                                        <span class="name">@if($user->userInfo){{$user->userInfo->nickname}}@endif</span>
                                        <img class="sex" src="{{url('/images/admin/girl.gif')}}" alt="" style="">
                                    </p>
                                </div>
                            </td>
                            <td>{{$user->phone}}</td>
                            <td>@if($user->userInfo){{$user->userInfo->realname}}@endif</td>
                            <td>@if($user->userInfo){{$user->userInfo->constellation}}@endif</td>
                            <td>@if($user->userInfo){{$user->userInfo->province}}{{$user->userInfo->city}}{{$user->userInfo->area}}@endif</td>
                            <td>
                                @if($user->userInfo)
                                    @if($user->userInfo->sex == 1)
                                        男
                                    @else
                                        女
                                    @endif
                                @endif
                            </td>
                            <td>@if($user->userInfo){{$user->userInfo->books_coin}} @endif</>
                            <td>
                                @if($user->is_free == 0)
                                    <a href="javascript:;" class="free" data-id="{{$user->id}}"><p style="color: red;">收费</p></a>
                                @else
                                    <a href="javascript:;" class="free" data-id="{{$user->id}}"><p style="color: green;">免费</p></a>
                                @endif
                            </td>
                            <td>
                                @if(is_null($user->user_vip))
                                    <a href="javascript:;" onclick="upPop({{$user->id}})"><span style="color: orange;">设置VIP</span></a>
                                    @else
                                   <a href="javascript:;" data-id="{{$user->user_vip->id}}" class="del_vip"><span style="color: #72b3ff;">取消VIP</span></a>
                                @endif
                            </td>
                            <td>{{$user->created_at}}</td>
                            <td>@if((int)$user->status == 0)<span class="color3">锁定</span> @elseif((int)$user->status == 1)<span class="color4">正常</span>@endif</td>
                            {{--<td><a class="btnLump btnLump1" href="">删除｜锁定</a></td>--}}
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $users->render(); ?>
        </div>
    </div>
    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian" style="height:400px;">
            <input type="hidden" name="id" id="the_user_id" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3>vip内容设置</h3>

            <div class="fill-list">
                <span class="fill-tit">VIP时长</span>
                <select name="classify_id" id="vip_id">
                    @if(count($vip_rules) > 0)
                        @foreach($vip_rules as $vip_rule)
                            <option value="{{$vip_rule->id}}">{{$vip_rule->name}}</option>
                        @endforeach
                    @endif
                </select>
            </div>
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>
    <!-- content end -->
    <script>
        function upPop(userId){
            $('#the_user_id').val(userId);
            $('.upPop-box').upPop();
        }

        $(function(){
            //Api.Admin.sys.delUserVip
            $(document).on('click','.del_vip',function(){
                var vipId  = $(this).data("id");
                $.ajax({
                    url:'{{route("Api.Admin.sys.delUserVip")}}',
                    type:'post',
                    dataType:'json',
                    data:{vip_id:vipId},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({type:obj.level,text:obj.message,timeout:600});
                            window.location.reload();
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }
                });
            });

            $('#sou_btn').click(function () {
                var nickname  = $("#nickname").val();
                window.location.href = "{{route('Admin.Home.userList')}}?keyword="+nickname;
            });

            //Api.Admin.sys.setUserVip
            $(document).on('click','#subThisForm',function(){
                var vipId  = $('#vip_id option:selected').val();
                var userId = $('#the_user_id').val();
                $.ajax({
                    url:'{{route("Api.Admin.sys.setUserVip")}}',
                    type:'post',
                    dataType:'json',
                    data:{user_id:userId,vip_id:vipId},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({type:obj.level,text:obj.message,timeout:600});
                            window.location.reload();
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }
                });
            });
            $(document).on('click','.free',function(){
                var id = $(this).attr('data-id');
                $.ajax({
                    url:'{{route("Api.Admin.sys.setUserFree")}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({type:obj.level,text:obj.message,timeout:600});
                            window.location.reload();
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }
                });
            });
        });
    </script>

@endsection